package teach.sort;

import java.util.Arrays;

public class InsertionSort2 {
    public static void main(String[] args) {
        int[] array = {8, 1, 4, 9, 0, 3, 5, 2, 7, 6};

        sortByNtemp(array);
        //sortBy1Temp(array);
    }

    public static void sortByNtemp(int[] array){
        for(int i=1;i< array.length;i++){
            for(int j=i;j>0;j--){
                if(array[j]<array[j-1]){
                    int temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;
                    System.out.println(Arrays.toString(array));
                }else{
                    break;
                }
            }
            System.out.println();
        }
    }

    public static void sortBy1Temp(int[] array){
        for(int i=1;i< array.length;i++){
            int temp = array[i];
            int j = i;
            for(;j>0;j--){
                if(temp<array[j-1]){
                    array[j] = array[j-1];
                    System.out.println(Arrays.toString(array));
                }else{
                    break;
                }
            }
            array[j] = temp;
            System.out.println(Arrays.toString(array));
            System.out.println();
        }
    }
}
